home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / Tools / Preditor 2.0 / Macros / Key Assignment Examples < prev    next >
Encoding:
Text File  |  1991-12-31  |  3.9 KB  |  162 lines  |  [TEXT/TCEd]

  1. #
  2. #    Key Assignment Examples
  3. #
  4. #    Last Modified: Friday, June 27, 1991 at 11:46 PM
  5. #    Macro Files for Preditor
  6. #
  7. #
  8. #    © Copyright Evatac Software  1988-1991
  9. #    All rights reserved
  10. #
  11.  
  12. #  The following are some example macros that you would commonly
  13. #  assign to a keystroke.  They demonstrate how you can write 
  14. #  simple  macros to maniuplate the cursor position, insert
  15. #  text etc.
  16. #
  17. #  You can changes the key assignments by using the 'Assign
  18. #  Menus & Keys' command in the Special Menu to obtain the
  19. #  keycode and modifier value, and replace the ones given below
  20. #  (after the AddMenu command)
  21.  
  22. #
  23. # Electric {
  24. #
  25. # Electrically insert a left bracket for C source code.
  26. # There are two methods, uncomment/comment the one you want.
  27. #
  28. # Method #1: if () {
  29. #                |        <-- Insertion Point
  30. # Method #2: if ()
  31. #             {
  32. #                |        <-- Insertion Point
  33. #
  34. # Assigned to: '{'
  35.  
  36. AddMenu "Electric {" # 33 2
  37.     saveHighlight = ~Highlighting
  38.     ~Highlighting = 0
  39.         
  40.     If (Position("p", "start", §, ~Active) == ∂
  41.         Position("p", "end",   §, ~Active) && ∂
  42.         (!Valid(§:[§]≥1, ~Active) || Select(§, ~Active) == "\n"))
  43.         
  44.         /* Get the space/tabs at the beginning of the current   */
  45.         /* line.                                                */
  46.         
  47.         Mark("y", [§]≤0, "_LB_", ~Active)
  48.         Search("bp", "^[ \\t]+", NULL, ~Active)
  49.         Copy(§, ~Active)
  50.  
  51.         /* There are two methods for placing the left bracket.  */
  52.         /* Comment/Uncomment them based on your preference        */
  53.         
  54.         /* Method #1 : Place left bracket on same line as          */
  55.         /* the conditional statement                            */
  56.         
  57.         Insert("{\n" + Clipboard(~Clipboard) + "\t", @"_LB_", ~Active)
  58.  
  59.         /* Method #2: Place left bracket on the next line, lined */
  60.         /* up with the left edge of the current line, then tab   */
  61.         /* in on the next line to begin inserting text             */
  62.         
  63. #        Insert("\n" + Clipboard(~Clipboard) + "{\n" ∂
  64. #                    + Clipboard(~Clipboard) + "\t", @"_LB_", ~Active)
  65.     Else
  66.         Key(123, [§]≤0, ~Active)
  67.     End
  68.     
  69.     Unmark("", "_LB_", ~Active)
  70.     ~Highlighting = saveHighlight
  71. EndMenu
  72.  
  73. #
  74. # Electric }
  75. #
  76. # Electrically line up the right bracket with the matching
  77. # line containing the left bracket for C source code.  For example
  78. #
  79. #         if () {
  80. #            x = 3;            ( Typing '}' will place        )
  81. #        }                <-- ( '}' here                    )
  82. #
  83. # Assigned to: '}'
  84.  
  85. AddMenu "Electric }" # 30 2
  86.     saveHighlight = ~Highlighting
  87.     ~Highlighting = 0
  88.         
  89.     If (Position("p", "start", §, ~Active) == ∂
  90.         Position("p", "end",   §, ~Active) && ∂
  91.         (!Valid(§:[§]≥1, ~Active) || Select(§, ~Active) == "\n"))
  92.  
  93.         Mark("y", §, "_RB_", ~Active)
  94.         Insert("}", [§]≤0, ~Active)
  95.         Select(§:[§]≤1, ~Active)
  96.         Match(NULL, §, ~Active)
  97.         Search("bp", "^[ \\t]+", NULL, ~Active)
  98.         Copy(§, ~Active)
  99.         Select(@"_RB_", ~Active)
  100.         
  101.         /* Now see if there is any previous text on the line.  If  */
  102.         /* so, insert the bracket on the next line                   */
  103.         
  104.         origPos = Position("p", "start", §, ~Active) 
  105.         Search("pb", "^[ \\t]+", NULL, ~Active)
  106.         
  107.         If (origPos != Position("p", "end", §, ~Active))
  108.             
  109.             /* Place on new line */
  110.         
  111.             Select([@"_RB_"]≤0, ~Active)
  112.             Insert("\n" + Clipboard(~Clipboard), §, ~Active)
  113.  
  114.         Else
  115.             Paste(§, ~Active)
  116.         End
  117.         
  118.         Insert("\n" + Clipboard(~Clipboard), [§]≥1, ~Active)
  119.         
  120.     Else
  121.         Key(125, [§]≤0, ~Active)
  122.     End
  123.     
  124.     Unmark("", "_RB_", ~Active)
  125.     ~Highlighting = saveHighlight
  126. EndMenu
  127.  
  128. #
  129. # Electric ;
  130. #
  131. # Electrically place a semi colon, insert a new line and
  132. # indent to the proper insertion point.  For Example
  133. #
  134. #         x = 3;                (Typing the ';' here will 
  135. #        |                <-- (place the insertion point here
  136. #
  137. # Assigned to: ';'
  138.  
  139. AddMenu "Electric ;"
  140.     /* These lines can be commented out if you normally     */
  141.     /* have auto indent on                                    */
  142.     NewFormat("y", "U", NULL, NULL, NULL, "current", ~Active)
  143.     Format("d", "current", ~Active)
  144.     DeleteFormat("current")
  145.     
  146.     Insert(";", §, ~Active)
  147.     Key(13, §, ~Active)
  148. EndMenu
  149.  
  150.  
  151. #
  152. # Goto SelectedMarker
  153. #
  154. # Jumps to the marker in the activate document that has the name
  155. # of the current selection
  156. #
  157. # Assigned to: <control> M
  158.  
  159. AddMenu "Goto Selected Marker" 46 16
  160.     selection = Select(§, ~Active)
  161.     Select(@selection, ~Active)
  162. EndMenu